package com.gangan.service.impl;

import com.gangan.mapper.DoctorMapper;
import com.gangan.model.Doctor;
import com.gangan.model.Order;
import com.gangan.mapper.OrderMapper;
import com.gangan.model.Patient;
import com.gangan.model.Section;
import com.gangan.service.IOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-08-20
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
    @Autowired
    DoctorMapper doctorMapper;

    @Autowired
    OrderMapper orderMapper;

    @Override
    public boolean updateById(Order entity) {
        //如果订单是已完成 状态3，更新医生接单数量
        if (entity.getStatus().equals(3)){
            Doctor doctor = doctorMapper.selectById(entity.getDoctorId());
            if (doctor!=null){
                doctor.setServiceNum(doctor.getServiceNum()+1);
                doctorMapper.updateById(doctor);
            }

        }
        return super.updateById(entity);
    }

    @Override
    public List<Doctor> querydocBydep(String department) {

        return orderMapper.querydocBydep(department);

    }


    /**
     * 根据状态或者id或者预约人来查询订单
     * @return
     */
    @Override
    public List<Map> getOrderByOthers(String patientName,Integer status,Integer id) {

        return orderMapper.getOrderByOthers( patientName, status, id);

    }
}
